package com.own.business.wallet.business.util.lock;

import com.own.component.store.core.util.LockStoreUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.function.Supplier;

/**
 * WalletLockUtil
 *
 * @author chenxueli
 * @date 2023-07-28 14:34:00
 */
@Slf4j
@Component
public class OrderLockUtil {

    @Resource
    private LockStoreUtil lockStoreUtil;

    /**
     * 使用订单锁信息
     *
     * @param order    订单号
     * @param runnable 执行的方法
     */
    public void lock(String order, Runnable runnable) {
        lockStoreUtil.lock("lock:order:" + order, runnable);
    }

    /**
     * 使用订单锁信息
     *
     * @param order    订单号
     * @param runnable 执行的方法
     */
    public <T> void operation(String order, Supplier<T> runnable) {
        lockStoreUtil.lock("lock:order:" + order, runnable);
    }

}
